var pageNum=0; //当前页
var totalPages=0; //总页数
var totalElements=0;//总记录数
var number=0;//当前页
$(function () {
    bindPlaceInfo(0);
    clickFind();
    page(totalElements,5);
 /*   upPage(pageNum);
    nextPage(pageNum);*/
   // page();
})
/**
 * 绑定场地信息
 */
function bindPlaceInfo(pageNum){
    var auditorstatus=$("#auditorstatus").val();
    $.ajax({
        type:"GET",
        url:"/place/findPlaceInfo" ,
        data:{auditorstatus:auditorstatus,pageNum:pageNum,type:"person"},
        dataType:"json",
        async:false,
        success:function(data){
            $("#tbody").html("");
            totalElements=data.totalElements;
            number=data.number;
            $.each(data.content,function (i,e) {
                var placeStatus;
                if(e.status==1){
                    placeStatus="可用";
                }else{
                    placeStatus="占用";
                }
                var auditorstatus;
                var disable;
                if(e.auditorstatus==1){
                    auditorstatus="正在审核";
                }else if(e.auditorstatus==2){
                    auditorstatus="审核失败";
                }else if(e.auditorstatus==3){
                    auditorstatus="审核成功";
                }
                var more1;
                var more2;
                var more3;
                if(e.more1==undefined){
                    more1="";
                }else{
                    more1=e.more1
                }
                if(e.more2==undefined){
                    more2="";
                }else{
                    more2=e.more2;
                }
                if(e.more3==undefined){
                    more3="";
                }else{
                    more3=e.more3;
                }
                $("#tbody").append("<tr>" +
                    "<td width=\"100px\">"+e.placename+"</td>" +
                    "<td width=\"150px\">"+more1+more2+more3+"</td>" +
                    "<td width=\"200px\">"+e.address+"</td>" +
                    "<td width=\"80px\">"+e.rownum+"</td>" +
                    "<td width=\"80px\">"+e.columnnum+"</td>" +
                    "<td width=\"80px\">"+placeStatus+"</td>" +
                    "<td width=\"80px\">"+auditorstatus+"</td>" +
                    "<td width=\"180px\">"+e.agintName+"</td>" +
                    "<td width=\"80px\">"+e.entertime+"</td>" +
                    "<td>" +
                    "<a href='/page/MySeatAdd?placeId="+e.placeid+"' title='查看'  class='btn btn-xs btn-status'>查看</a>" +
                    "</td>" +
                    "</tr>");
            })
            totalPages=data.totalPages;
        },
        error:function (data) {
            alert("网络加载失败");
        }
    });
}

/**
 * 点击搜索按钮
 */
function clickFind(){
    $("#Sel").click(function () {
        bindPlaceInfo(pageNum);
        page(totalElements,5);
    })
}


function page(totalElements,pageNum){
    layui.use(['laypage'], function(){
        var laypage = layui.laypage
        //执行一个laypage实例
        laypage.render({
            elem: 'page1' //注意，这里的 test1 是 ID，不用加 # 号
            ,count: totalElements //数据总数，从服务端得到
            ,layout: ['count', 'prev', 'page', 'next', 'skip']
            ,limit:pageNum  //每一页显示的条数
            ,skip:true
            ,jump: function(obj, first) {
                //obj包含了当前分页的所有参数，比如：
                console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
                console.log(obj.limit); //得到每页显示的条数
                var aaa=obj.curr-1;
                if(!first){

                    bindPlaceInfo(aaa);
                }
            }
        });
    });
}
